const fp = require('lodash/fp')

// 数据
// horsepower 马力,dollarValue 价格, inStock 库存
const cars = [{
        name: "Ferrari FF",
        horsepower: 660,
        dollarValue: 70000,
        inStock: true
    },
    {
        name: "Spyker c12 Zafato",
        horsepower: 650,
        dollarValue: 64800,
        inStock: false
    },
    {
        name: "Jaguar XKR-S",
        horsepower: 525,
        dollarValue: 132000,
        inStock: false
    },
    {
        name: "Audi R8",
        horsepower: 525,
        dollarValue: 114200,
        inStock: false
    },
    {
        name: "Aston Martin One-77",
        horsepower: 750,
        dollarValue: 1850000,
        inStock: true
    },
    {
        name: "Pagani Huayra",
        horsepower: 700,
        dollarValue: 130000,
        inStock: false
    },
]

// one 
const isLaseInStock = fp.flowRight(fp.prop("inStock"), fp.last)

// const value = isLaseInStock(cars)

// two
const getFirstName = fp.flowRight(fp.prop("name"), fp.first)

// const value = getFirstName(cars)

// three
const _average = (xs) => {
    return fp.reduce(fp.add, 0, xs) / xs.length
}

const averageDollarValue = fp.flowRight(_average, fp.map(fp.prop("dollarValue")))

// const value = averageDollarValue(cars)

// four
const _underscore = fp.replace(/\W+/g, "_")

const sanitizeNames = fp.map(fp.flowRight( _underscore,fp.lowerCase, fp.prop("name")))

const value = sanitizeNames(cars)
console.log(value)